package com.site_assembly.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.service.form.DcsiteForm;
import com.site_assembly.dao.DcsiteMapper;
import com.site_assembly.entity.Dcsite;
import com.site_assembly.service.IDcsiteService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 区县站点信息表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-09-20
 */
@Service
public class DcsiteServiceImpl extends ServiceImpl<DcsiteMapper, Dcsite> implements IDcsiteService {

    @Resource
    private DcsiteMapper dcsiteMapper;

    @Override
    public IPage findAllDcSiteByPageAndOperatingState(String operatingState, Integer current, Integer pageSize) {

        UpdateWrapper<Dcsite> updateWrapper = new UpdateWrapper<>();
        updateWrapper.like("operating_state",operatingState);
        IPage<Dcsite> page = new Page<>(current,pageSize);

        return dcsiteMapper.selectPage(page, updateWrapper);
    }

    @Override
    public Integer addDcSite(DcsiteForm dcsiteForm) {

        Dcsite dcsite = new Dcsite();
        BeanUtils.copyProperties(dcsiteForm,dcsite);


        return dcsiteMapper.insert(dcsite);
    }

    @Override
    public Integer setDcSiteOfOperatingStateByDcSiteNumber(String dcSiteNumber, String operatingState) {

        UpdateWrapper<Dcsite> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("operating_state",operatingState).eq("dcsite_number",dcSiteNumber);

        return dcsiteMapper.update(null,updateWrapper);
    }
}
